<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2018/5/11
 * Time: 15:59
 */

namespace app\admin\model;


use think\Model;

class Userbg extends Model
{
    /**
     * 分页展示  从第$rows*($page-1)条开始，展示$rows条
     * @param $page 页数
     * @param $rows 每页展示的记录条数
     * @return mixed
     */
    public static function getUserbgList($page,$rows){
        $userbgList = self::limit($rows*($page-1),$rows)->select();
        return $userbgList;
    }
    
    /**
     * 统计总记录数
     * @return int
     */
    public static function getTotalNum(){
        $total = self::count();
        return $total;
    }
    
    /**
     * 插入新增图片
     * @param $data
     * @return false|int
     */
    public static function insertBg($data){
        $Userbg = new Userbg();
        $res = $Userbg->save($data);
        return $res;
    }
    
    /**
     * 根据id获取该记录的bgpic
     * @param $id
     * @return array
     */
    public static function getColumn($id){
        $url = Userbg::where('id', $id)->column('bgpic');
        return $url;
    }
    /**
     * 根据id删除图片
     * @param $id 被删除图片的id
     * @return int
     */
    public static function deleteBg($id){
        $Userbg = Userbg::get($id);
        return $Userbg->delete();
    }
}